/************************************************************
 * @file: nvsns_controller.h
 * @author: Hao
 * @version: V0.0
 * @data: 2023/07/28
 * @brief: novosns controller lib header file
 * @note:
 * @Copyright (C) 2023 Novosense All rights reserved.
 ************************************************************/

/************************************************************
 ************************************************************
 * @par Edition History
 * -V0.0  2023.07.28
 *        - Initilization file for nvsns controller 
 *
 ************************************************************/
 

#ifndef __NVSNS_CONTROLLER_H__
#define __NVSNS_CONTROLLER_H__

#include "nvsns_mmlib.h"

#define DEBUG_PARAMETER_ENABLE 0

typedef struct 
{
    // Inputs: Coefficients
    Frac16_t Kp;
    Frac16_t Ki;
    Frac16_t Kd;

    // Inputs: Output saturation limits
    Frac16_t Max;
    Frac16_t Min;

    // Inputs: 
    Frac16_t Ref;
    Frac16_t Fdbk;

    // Internal values
    Frac16_t B2;
    Frac16_t B1;
    Frac16_t B0;

    Frac16_t Out1;

    Frac16_t Errn;
    Frac16_t Errn1;
    Frac16_t Errn2;

    // Output values
    Frac16_t Out;

} PidIncremental_t;

void PID_IncrementalInit(PidIncremental_t *tPid);
void PID_IncrementalUpdate(PidIncremental_t *tPid);

typedef struct 
{
    // Inputs: Coefficients
    Frac16_t Kp;
    Frac16_t Ki;
    Frac16_t Kd;

    // Inputs: Output saturation limits
    Frac16_t Max;
    Frac16_t Min;
    
    Frac16_t InterMax;
    Frac16_t InterMin;
    
    // Inputs: 
    Frac16_t Ref;
    Frac16_t Fdbk;
    
    // Internal values
    Frac16_t Inter;
    Frac16_t Errn;
    Frac16_t Errn1;

    // Output values
    Frac16_t Out;

} PidPositional_t;

void PID_PidPositionalInit(PidPositional_t *tPid);
void PID_PositionalUpdate(PidPositional_t *tPid);
#endif

